//
//  AirTabBarController.m
//  Daiqile
//
//  Created by daiqile on 2016/11/14.
//  Copyright © 2016年 com.daiqile.daiqile. All rights reserved.
//

#import "AirTabBarController.h"
#import "AirNavigationController.h"

#import "MainViewController.h"
#import "InvestViewController.h"
#import "DiscoverViewController.h"
#import "MineViewController.h"
@interface AirTabBarController ()<UITabBarControllerDelegate>


@end

@implementation AirTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    
    // 添加所有的子控制器
    [self setupChildVcs];
    
    [self setupItem];

}

- (void)setupChildVcs
{
//    [self setupChildVc:[[MainViewController alloc] init] title:@"推荐" image:@"推荐" selectedImage:@"推荐_s"];
//
//    [self setupChildVc:[[InvestViewController alloc] init] title:@"投资" image:@"投资" selectedImage:@"投资_s"];
//
//    [self setupChildVc:[[DiscoverViewController alloc] init] title:@"发现" image:@"发现更多" selectedImage:@"发现更多_s"];
//
//    [self setupChildVc:[[MineViewController alloc] init] title:@"我的" image:@"我的" selectedImage:@"我的_s"];
    [self setupChildVc:[[MainViewController alloc] init] title:@"推荐" image:@"推荐X" selectedImage:@"推荐X_s"];
    
    [self setupChildVc:[[InvestViewController alloc] init] title:@"投资" image:@"投资X" selectedImage:@"投资X_s"];
    
    [self setupChildVc:[[DiscoverViewController alloc] init] title:@"发现" image:@"发现X" selectedImage:@"发现X_s"];
    
    [self setupChildVc:[[MineViewController alloc] init] title:@"我的" image:@"我的X" selectedImage:@"我的X_s"];
}

- (void)setupChildVc:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
{
    AirNavigationController *nav = [[AirNavigationController alloc] initWithRootViewController:vc];
    
    [self addChildViewController:nav];
    
    nav.tabBarItem.title = title;
    
    nav.tabBarItem.image = [UIImage imageNamed:image];
    [nav.tabBarItem.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
    [nav.tabBarItem.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

/**
 * 设置item属性
 */
- (void)setupItem
{

    //设置tabbar背景色
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"TabBg"]];
    // UIControlStateNormal状态下的文字属性
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    
    // 文字颜色
    normalAttrs[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    
    // 文字大小
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
//
//    // UIControlStateSelected状态下的文字属性
    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
//    
//    // 文字颜色
    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
//    
//    // 统一给所有的UITabBarItem设置文字属性
//    // 只有后面带有UI_APPEARANCE_SELECTOR的属性或方法, 才可以通过appearance对象来统一设置
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
}


- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0){

    return YES;
}

- (void)tabBar:(UITabBar *)tabBar willBeginCustomizingItems:(NSArray<UITabBarItem *> *)items
{
    //NSLog(@"index == 111");
}

@end
